#!/bin/bash
#This is nginx install script
#date 2022-10-10
#editer guiping jiang
#read -p ""


#安装nginx需要的基础环境包
echo -e "\033[33m >>开始安装nginx需要的基础环境包...  \033[0m"
yum -y install gcc automake autoconf libtool make gcc-c++ >>/root/nginx-install.log 2>&1
#yum list installed |awk '{print $1}' > yum.log 2>&1
#egrep 'gcc|automake|autoconf|libtool|make|' yum.log
#a=`echo $?`
#	if [ $a -eq 0 ]
#	then
echo -e "\033[32m nginx需要的基础环境包安装成功... \033[0m"
#	else
#	echo -e "\033[32m nginx需要的基础环境包安装失败请检查... \033[0m"
#	exit
#	fi
#安装nginx需要依赖包
echo -e "\033[33m >>安装nginx需要3个依赖包分别如下： \033[0m"
printf  "\033[35m 1.prce \033[0m\n"
printf  "\033[35m 2.zlib \033[0m\n"
printf  "\033[35m 3.openssl \033[0m\n"
#下载prce包

read -p ">>请输入将pcre包安装到哪个目录？(请用绝对目录),例:'/usr/local': " DIR
cd $DIR
ls $DIR/pcre-8.38 >>/root/nginx-install.log 2>&1
f=`echo $?`
	if [ $f -eq 0 ]
	then 
	echo -e "\033[33m 已经安装了pcre \033[0m"
	else 
	echo -e "\033[33m >>3.开始下载安装pcre包 \033[0m"
	wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz >>/root/nginx-install.log 2>&1
	tar -zxf pcre-8.38.tar.gz && cd pcre-8.38
	./configure && make && make install >>/root/nginx-install.log 2>&1
	b=`echo $?`
		if [ $b -eq 0 ]
		then
		echo -e "\033[32m nginx的依赖包prce包已经安装成功 \033[0m"
		else
		echo -e "\033[31m nginx的依赖包prce包安装失败，请检查。\033[0m"
		exit
		fi
	
	fi

#下载安装zilb包

read -p "请输入将zlib包安装到哪个目录？(请用绝对目录): " DIR1
cd $DIR1
ls $DIR1/zlib-1.2.8 >>/root/nginx-install.log 2>&1
g=`echo $?`
	if [ $g -eq 0 ]
	then
	echo -e "\033[33m 已经安装了zlib包了 \033[0m"
	else
	echo -e "\033[33m >>2.开始下载安装zlib包... \033[0m"
	wget http://zlib.net/zlib-1.2.8.tar.gz >>/root/nginx-install.log 2>&1
	tar zxvf zlib-1.2.8.tar.gz && cd zlib-1.2.8
	./configure && make && make install >>/root/nginx-install.log 2>&1
	 c=`echo $?`
		if [ $c -eq 0 ]
		then
		echo -e "\033[32m nginx的依赖包zlib包已经安装成功..................... \033[0m"
		else
		echo -e "\033[31m nginx的依赖包zlib包安装失败，请检查。\033[0m"
		exit
		fi
	fi
#下载安装openssl

read -p "请输入将openssl包安装到哪个目录？(请用绝对目录): " DIR2
cd $DIR2
ls $DIR2/openssl-1.0.1g >>/root/nginx-install.log 2>&1
h=`echo $?`
	if [ $h -eq 0 ]
	then
	echo -e "\033[33m 已经安装了openssl包了..... \033[0m"
	else
	echo -e "\033[33m >>3.开始下载安装openssl包.... \033[0m"
	wget https://www.openssl.org/source/openssl-1.0.1g.tar.gz >>/root/nginx-install.log 2>&1
	tar zxvf openssl-1.0.1g.tar.gz >>/root/nginx-install.log 2>&1
 	d=`echo $?`
		if [ $d -eq 0 ]
		then
		echo -e "\033[32m nginx的依赖包openssl包已经安装成功.... \033[0m"
		else
		echo -e "\033[33m nginx的依赖包openssl包安装失败，请检查。\033[0m"
		exit
		fi
	fi
#下载安装nginx

read -p "请输入将nginx下载到哪个目录？(请用绝对目录): " DIR3
cd $DIR3
ls $DIR3/nginx-1.8.1 >>/root/nginx-install.log 2>&1
k=`echo $?`
	if [ $k -eq 0 ]
	then 
	echo -e "\033[33m 已经下载好了nginx \033[0m"
	else
	echo -e "\033[33m >>3.开始下载安装nginx包... \033[0m"
	wget http://nginx.org/download/nginx-1.8.1.tar.gz >>/root/nginx-install.log 2>&1
	tar zxf nginx-1.8.1.tar.gz
	cd nginx-1.8.1
	read -p "请输入编译到哪个目录？(请用绝对目录): " DIR4

	./configure --prefix=$DIR4 --sbin-path=$DIR4/nginx/sbin/nginx --conf-path=$DIR4/nginx/conf/nginx.conf --pid-path=$DIR4/nginx/nginx.pid --with-http_ssl_module --with-http_stub_status_module --with-pcre=$DIR/pcre-8.38 --with-zlib=$DIR1/zlib-1.2.8 --with-openssl=$DIR2/openssl-1.0.1g >>/root/nginx-install.log 2>&1
make &&make install >>/root/nginx-install.log 2>&1
 	e=`echo $?`
		if [ $e -eq 0 ]
		then
		echo -e "\033[32m nginx已经安装成功 \033[0m"
		else
		echo -e "\033[31m nginx安装失败，请检查。\033[0m"
		exit
		fi
	fi


